const moment = require('moment');
const db = require('../dbbase/db');
const getData = require("../util/data");

//获取每天指标信息
exports.getTargetDayInfo = (req, res, next) => {
    const startDate = getData.getCurrentMonthFirst();
    const endDate = getData.getCurrentMonthLast();
    const sql = "select to_char(t.BTIME, 'YYYY-MM-DD') 日期,COUNT(*) 产量,COUNT(PDID) 缺陷量,COUNT(1)-COUNT(PDID) 有效产出  from mwdk_pa_work_library t "
        + "WHERE t.btime between TO_DATE('" + startDate + "','yyyy-mm-dd HH24:mi:ss') and TO_DATE('" + endDate + "','yyyy-mm-dd HH24:mi:ss') "
        + "and MATE_TYPE not like '%去毛刺%' "
        + "group by to_char(t.BTIME, 'YYYY-MM-DD') "
        + "ORDER BY 日期 asc "
    const params = [];
    db.query(sql, params).then((result) => {
        res.status(200).json(result)
    }).catch((err) => {
        console.log(err);
    });
}
exports.getTargetMouthInfo = (req, res, next) => {
    const startDate = getData.getCurrentMonthFirst();
    const endDate = getData.getCurrentMonthLast();
    const sql = "select COUNT(*) totle,COUNT(PDID) quelity,COUNT(1)-COUNT(PDID) outTotle  from mwdk_pa_work_library t "
        + "WHERE t.btime between TO_DATE('" + startDate + "','yyyy-mm-dd') and TO_DATE('" + endDate + "','yyyy-mm-dd') "
        + "and MATE_TYPE not like '%去毛刺%' "
    const params = [];
    db.query(sql, params).then((result) => {
        res.status(200).json(result)
    }).catch((err) => {
        console.log(err);
    });
}

